package com.example.elk.schedule;


import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/8/31 09:37
 */
@EnableScheduling
@Slf4j
@Component
public class Task {

    @Value("${server.tomcat.accesslog.directory}")
    public String logDirectory;

    /**
     * 启动延迟10s,然后每隔30s执行一次
     */
    @Scheduled(initialDelay = 10L, fixedRate = 1000*30*1L)
    public void cleanLog(){
        log.info("loggerDirectory!!!!!!!:{}",logDirectory);
        File file=new File(logDirectory);
        if(file.isDirectory()){
            File[] files = file.listFiles();
            for (File file1 : files) {
                log.info("logPath:{}",file1.getAbsolutePath());
                log.info("测试日志file:{}",JSON.toJSONString(file1));
            }
        }
    }

}
